package com.xinqi.modules.course.textbook.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.textbook.client.CourseCloudTextbookContentClient;
import com.xinqi.modules.course.textbook.dto.req.CourseCloudTextbookContentCreateDTO;
import com.xinqi.modules.course.textbook.dto.req.CourseCloudTextbookContentQueryDTO;
import com.xinqi.modules.course.textbook.dto.req.CourseCloudTextbookContentUpdateDTO;
import com.xinqi.modules.course.textbook.dto.rsp.CourseCloudTextbookContentResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 课程模块云课本课堂内容降级处理
 *
 * @author: wenjie
 * @date: 2023/05/30
 */
@Slf4j
@Component
public class CourseCloudTextbookContentFallbackFactory implements FallbackFactory<CourseCloudTextbookContentClient> {

    @Override
    public CourseCloudTextbookContentClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new CourseCloudTextbookContentClient() {
            @Override
            public R<PageInfo<CourseCloudTextbookContentResultDTO>> page(CourseCloudTextbookContentQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<CourseCloudTextbookContentResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(CourseCloudTextbookContentCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, CourseCloudTextbookContentUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
